package com.apes.enquiry.supplier;

import com.alibaba.fastjson.JSONObject;
import com.apes.enquiry.supplier.santouliubi.SantouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 类描述：
 *
 * @ClassName SupplierCallbackController
 * @Description https://test-ssp.jekunauto.cn
 * @Author wushilong
 * @Date 2022/12/19 10:41
 * @Version 1.0
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/thirdparty")
public class SupplierCallbackController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private SantouService santouService;

    /**
     * 测试方法
     * @param name
     * @param map
     * @return
     */
    @RequestMapping(value = "/{name}/santou")
    public Map<String, Object> test(@PathVariable("name") String name, @RequestBody Map<String, Object> map) {
        if (name.equals("test")) {
            System.out.println(name);
            System.out.println(map);
        }
        return map;
    }

    @RequestMapping(value = "/{name}/enroll")
    @Transactional
    public JSONObject enroll(@PathVariable("name") String name, @RequestBody JSONObject json) {
        if ("santou".equals(name)){
            return santouService.entrance(json);
        }

        /*Document document = new Document();//记录Mongo
        document.put("result",json);
        mongoTemplate.getCollection("enrollConnection").insertOne(document);*/
        return santouService.entrance(json);
    }

}
